var t = getApp();

Page({
    data: {
        addressShow: !1,
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        retCity: "",
        auctionValue: {
            name: "",
            phone: "",
            retCity: "",
            agreementChoose: !1
        },
        uploadUrl: "upload.uploadPic",
        showphone: !1,
        yazshop: "",
        shenqShow: !1,
        real_name: "",
        province_id: "",
        city_id: "",
        district_id: "",
        address: "",
        identity_card: "",
        company: "",
        positive: "",
        back: "",
        holdID: "",
        license: "",
        remark: "",
        agreement: "",
        banner_img: ""
    },
    onLoad: function(t) {
        this._initAddressInfo();
    },
    getverifyGoods: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.index.getAuctionData");
        t._postNetWork({
            url: e,
            data: {
                art: "verifyGoods"
            },
            success: function(e) {
                var s = e.data;
                a.getAgreement(), 1 == s.result ? console.log(s, "可以申请") : (console.log(s, "需要购买指定商品才能申请"), 
                wx.showModal({
                    title: s.msg.msg,
                    success: function(a) {
                        a.confirm ? (wx.showLoading({
                            title: "加载中"
                        }), console.log("用户点击确定"), t._isTextEmpty(s.msg.url) ? wx.reLaunch({
                            url: "/packageG/member_v2/member_v2",
                            success: function(t) {
                                wx.hideLoading({
                                    success: function(t) {}
                                });
                            }
                        }) : wx.navigateTo({
                            url: "/packageA/detail_v2/detail_v2?id=" + s.msg.url[0].split("goods/")[1].split("?")[0],
                            success: function(t) {
                                wx.hideLoading({
                                    success: function(t) {}
                                });
                            }
                        })) : a.cancel && (console.log("用户点击取消"), wx.navigateBack({
                            delta: 1
                        }));
                    }
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    isString: function(t) {
        return t instanceof String || "string" == typeof t;
    },
    street: function(t) {
        this.setData({
            street: t.detail.value
        });
    },
    isArray: function(t) {
        return t instanceof Array;
    },
    tapoff: function(t) {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    address: function(t) {
        this.setData({
            address: t.detail.value
        });
    },
    streetChoose: function() {
        console.log(this.data.auctionValue), t._isTextEmpty(this.data.auctionValue) ? wx.showToast({
            icon: "none",
            title: "请先选择所在地区",
            duration: 1500
        }) : this.setData({
            streetShow: !0,
            opren: !1
        });
    },
    streetClose: function(t) {
        this.setData({
            streetShow: !1,
            opren: !0
        });
    },
    _getStreet: function(a) {
        var e = this, s = t.getNetAddresss("member.memberAddress.street");
        s += "&district_id=" + a, t._getNetWork({
            url: s,
            success: function(a) {
                var s = a.data;
                1 != s.result || t._isTextEmpty(s.data) ? e.setData({
                    isShowStreet: !1
                }) : !t._isTextEmpty(s.data) && s.data.length > 0 ? e.setData({
                    districtVal: s.data,
                    isShowStreet: !0
                }) : e.setData({
                    isShowStreet: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    streetConfirm: function(t) {
        var a = t.target.dataset.strname;
        console.log(a, t.target.dataset.info.id), this.setData({
            streetId: t.target.dataset.info.id,
            street: a,
            streetShow: !1
        });
    },
    identity_card: function(t) {
        this.setData({
            identity_card: t.detail.value
        });
    },
    mobile: function(t) {
        this.setData({
            mobile: t.detail.value
        });
    },
    real_name: function(t) {
        this.setData({
            real_name: t.detail.value
        });
    },
    company: function(t) {
        this.setData({
            company: t.detail.value
        });
    },
    Chooseinp: function() {
        this.setData({
            "auctionValue.agreementChoose": !this.data.auctionValue.agreementChoose
        });
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    onClicksQ: function() {
        this.setData({
            shenqShow: !1
        });
    },
    shenqShow: function() {
        this.setData({
            shenqShow: !0
        });
    },
    addressShowbtn: function() {
        this.setData({
            addressShow: !0
        });
    },
    isCoverLayer: function() {
        this.setData({
            showphone: !1
        });
    },
    resultAdd: function() {
        var t = this.data.selectAddressData, a = t[0].name + " " + t[1].name + " " + t[2].name;
        this.setData({
            "auctionValue.retCity": a,
            addressShow: !1,
            province_id: t[0].id,
            city_id: t[1].id,
            district_id: t[2].id
        }), this._getStreet(t[2].id);
    },
    _initAddressInfo: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("地址信息准备就绪"), a._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), t._getNetWork({
                    url: t.getNetAddresss("member.member-address.address"),
                    success: function(t) {
                        var e = t.data, s = e.data.province, i = e.data.city, o = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: i
                        }), wx.setStorage({
                            key: "districtData",
                            data: o
                        }), a._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    provinceData: a.data
                }), t.setData({
                    "selectAddressData[0].name": a.data[t.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": a.data[t.data.pickerValue[0]].id,
                    "selectAddressData[0].index": t.data.pickerValue[0]
                }), t._getCityData();
            }
        });
    },
    _getCityData: function() {
        var t = this.data.selectAddressData[0];
        console.log("城市", "_data", t);
        var a = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("城市数据筛选", s), a.setData({
                    cityData: s
                }), a.setData({
                    "selectAddressData[1].name": s[a.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[a.data.pickerValue[1]].id,
                    "selectAddressData[1].index": a.data.pickerValue[1]
                }), a._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var t = this.data.selectAddressData[1];
        console.log("地区", "_data", t), console.log(t);
        var a = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("地区数据筛选", s), a.setData({
                    districtData: s
                }), console.log("districtData", s), a.setData({
                    "selectAddressData[2].name": s[a.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[a.data.pickerValue[2]].id,
                    "selectAddressData[2].index": a.data.pickerValue[2]
                }), console.log("over", a.data.selectAddressData);
            }
        });
    },
    bindChange: function(t) {
        var a = t.detail.value;
        this.data.pickerValue[0] != a[0] && (a[1] = 0, a[2] = 0), this.data.pickerValue[1] != a[1] && (a[2] = 0), 
        this.setData({
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        }), this._initAddressInfo();
    },
    remarkinp: function(t) {
        this.setData({
            remark: t.detail.value
        });
    },
    onRead: function() {
        var a = this, e = t.getNetAddresss(a.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var s = t.tempFilePaths;
                console.log(s);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        1 == e.result ? a.setData({
                            fileList1: e.data.img_url,
                            positive: e.data.img_url
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_1: function() {
        var a = this, e = t.getNetAddresss(a.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var s = t.tempFilePaths;
                console.log(s);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        1 == e.result ? a.setData({
                            fileList2: e.data.img_url,
                            back: e.data.img_url
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_2: function() {
        var a = this, e = t.getNetAddresss(a.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var s = t.tempFilePaths;
                console.log(s);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        1 == e.result ? a.setData({
                            fileList3: e.data.img_url,
                            holdID: e.data.img_url
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_3: function() {
        var a = this, e = t.getNetAddresss(a.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var s = t.tempFilePaths;
                console.log(s);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        1 == e.result ? a.setData({
                            fileList4: e.data.img_url,
                            license: e.data.img_url
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getverifyGoods();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    apply: function() {
        var a = this;
        if (a.data.auctionValue.agreementChoose) {
            var e = {
                art: "apply",
                real_name: a.data.real_name,
                mobile: a.data.mobile,
                province_id: a.data.province_id,
                city_id: a.data.city_id,
                district_id: a.data.district_id,
                address: a.data.address,
                identity_card: a.data.identity_card,
                company: a.data.company,
                positive: a.data.positive,
                back: a.data.back,
                holdID: a.data.holdID,
                license: a.data.license,
                remark: a.data.remark,
                street_id: a.data.streetId
            }, s = t.getNetAddresss("plugin.auction.api.index.getAuctionData");
            t._postNetWork({
                url: s,
                data: e,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? a.setData({
                        showphone: !0
                    }) : wx.showToast({
                        title: e.msg,
                        icon: "none",
                        duration: 1e3
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else wx.showToast({
            title: "请阅读并勾选申请协议",
            icon: "none",
            duration: 1e3
        });
    },
    getAgreement: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.index.getAuctionData");
        t._postNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    agreement: e.data.getAgreement.agreement,
                    banner_img: e.data.getAgreement.banner_img
                }), 0 == e.data.is_apply && a.getApply()) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getYanz: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.auctioneer.verifyGoods");
        t._postNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), a.setData({
                    yazshop: 1,
                    showphone: !0
                })) : (a.setData({
                    yazshop: 0
                }), wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getApply: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.index.getAuctionData");
        t._postNetWork({
            url: e,
            data: {
                art: "getApply"
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    real_name: e.data.getApply.real_name,
                    mobile: e.data.getApply.mobile,
                    province_id: e.data.getApply.district_id,
                    city_id: e.data.getApply.city_id,
                    district_id: e.data.getApply.district_id,
                    address: e.data.getApply.address,
                    identity_card: e.data.getApply.identity_card,
                    company: e.data.getApply.company,
                    positive: e.data.getApply.positive,
                    back: e.data.getApply.back,
                    holdID: e.data.getApply.holdID,
                    license: e.data.getApply.license,
                    remark: e.data.getApply.remark,
                    "auctionValue.agreementChoose": !0
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});